<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>我的购物车</title>
    <!-- 引入css 初始化的css 文件 -->
    <link rel="stylesheet" href="../css/base.css">
    <!-- 引入公共样式的css 文件 -->
    <link rel="stylesheet" href="../css/common.css">
    <!-- 引入car css -->
    <link rel="stylesheet" href="../css/car.css">
    <!-- 先引入jquery  -->
    <script src="../js/jquery.min.js"></script>
    <!-- 在引入我们自己的js文件 -->
    <script src="../js/car.js"></script>
    <style>
        .img {
            height: 110px;
        }
    </style>
</head>

<body>
</div>
<div class="c-container" id="app">
    <div class="w">
        <!-- 购物车主要核心区域 -->
        <div class="cart-warp">
            <!-- 头部全选模块 -->
            <div class="cart-thead">
                <div class="t-checkbox">
                    <input type="checkbox" class="checkall"> 全选
                </div>
                <div class="t-goods">商品</div>
                <div class="t-price">单价</div>
                <div class="t-num">数量</div>
                <div class="t-sum">小计</div>
                <div class="t-action">操作</div>
            </div>
            <!-- 商品详细模块 -->
            <div class="layuimini-container">
                <div class="layuimini-main">
                    <div class="cart-item-list" id="list">
                        <div class="cart-item check-cart-item" v-for="item in arr">
                            <div class="p-checkbox">
                                <input type="checkbox" checked class="j-checkbox">
                            </div>
                            <div class="p-goods">
                                <div class="p-img">
                                    <img :src="img+item[4]['img']" alt="图片加载失败" class="img">
                                </div>
                                <div class="p-msg" style="font-size: 20px">{{item[1]['dname']}}</div>
                            </div>
                            <div class="p-price" style="font-size: 14px">￥{{item[2]['price']}}</div>
                            <div class="p-num">
                                <div class="quantity-form">
                                    <a href="javascript:;" class="decrement">-</a>
                                    <input type="text" class="itxt" value="1">
                                    <a href="javascript:;" class="increment">+</a>
                                </div>
                            </div>
                            <div class="p-sum" style="font-size: 14px">￥{{item[2]['price']}}</div>
                            <div class="p-action"><a href="javascript:;">删除</a></div>
                        </div>

                        <!-- <div class="cart-item">
                             <div class="p-checkbox">
                                 <input type="checkbox" class="j-checkbox">
                             </div>
                             <div class="p-goods">
                                 <div class="p-img">
                                     <img src="upload/p2.jpg" alt="">
                                 </div>
                                 <div class="p-msg">【2000张贴纸】贴纸书 3-6岁 贴画儿童 贴画书全套12册 贴画 贴纸儿童 汽
                                 </div>
                             </div>
                             <div class="p-price">￥24.80</div>
                             <div class="p-num">
                                 <div class="quantity-form">
                                     <a href="javascript:;" class="decrement">-</a>
                                     <input type="text" class="itxt" value="1">
                                     <a href="javascript:;" class="increment">+</a>
                                 </div>
                             </div>
                             <div class="p-sum">￥24.80</div>
                             <div class="p-action"><a href="javascript:;">删除</a></div>
                         </div>
                         <div class="cart-item">
                             <div class="p-checkbox">
                                 <input type="checkbox" class="j-checkbox">
                             </div>
                             <div class="p-goods">
                                 <div class="p-img">
                                     <img src="upload/p3.jpg" alt="">
                                 </div>
                                 <div class="p-msg">唐诗三百首+成语故事全2册 一年级课外书 精装注音儿童版
                                     小学生二三年级课外阅读书籍
                                 </div>
                             </div>
                             <div class="p-price">￥29.80</div>
                             <div class="p-num">
                                 <div class="quantity-form">
                                     <a href="javascript:;" class="decrement">-</a>
                                     <input type="text" class="itxt" value="1">
                                     <a href="javascript:;" class="increment">+</a>
                                 </div>
                             </div>
                             <div class="p-sum">￥29.80</div>
                             <div class="p-action"><a href="javascript:;">删除</a></div>
                         </div>-->
                    </div>

                </div>
            </div>
            <!-- 结算模块 -->
            <div class="cart-floatbar">
                <div class="select-all">
                    <input type="checkbox" class="checkall">全选
                </div>
                <div class="operation">
                    <a href="javascript:;" class="remove-batch"> 删除选中的商品</a>
                    <a href="javascript:;" class="clear-all" @click="clearAll">清理购物车</a>
                </div>
                <div class="toolbar-right">
                    <div class="amount-sum">已经选<em>1</em>件商品</div>
                    <div class="price-sum">总价： <em></em></div>
                    <div class="btn-area"><a href="form-step.html">去结算</a></div>
                </div>
            </div>
        </div>
    </div>

</div>

<script src="../js/vue.js" charset="utf-8"></script>
<script src="../js/jquery.min.js"></script>
<script>

    //获取session
    var layuiSession = sessionStorage.getItem("dishes");
    var dishes = JSON.parse(layuiSession);
    let arr = []
    for (let i = 0; i < JSONLength(dishes); i++) {
        let keyid = "id" + i;
        arr[i] = dishes[keyid];
    }

    console.log(arr)
    console.log($('.price-sum').text())

    function JSONLength(obj) {
        var size = 0, key;
        for (key in obj) {
            if (obj.hasOwnProperty(key)) size++;
        }
        return size;
    };
    new Vue({
        el: "#app",
        data() {
            return {
                arr: arr,
                img: "../img/"
            }
        },
        methods: {
            clearAll() {
                sessionStorage.removeItem("dishes");
            }
        }
    })

</script>
</body>

</html>
